<?php
	header("Content-type:text/html; charset=utf8");
	require_once("../db/dbclass.php");
	require_once("../model/userinfo.php");
	require_once("../utils/common.php");
	$myDb=&DbController::getInstance();
	$username=$_POST['user_name'];
	$password=$_POST['user_password'];
	$email=$_POST['user_email'];
	$param="select * from yj_user_info where user_name ='".$username."'";
	$result_name = mysqli_num_rows($myDb->exec_query($param));
	$result_obj = new UserSign();
	if($result_name == 0){
		$param="select * from yj_user_info where user_email ='".$email."'";
		$result_email = mysqli_num_rows($myDb->exec_query($param));
		if($result_email == 0){
			$param="INSERT INTO yj_user_info (user_name,user_nickname,user_password,user_email) VALUES ('".$username."','".$username."','".$password."','".$email."')";
			$result = $myDb->exec_query($param);
			if($result ==TRUE){
				$param="select * from yj_user_info where user_name ='".$username."'";
				$result = $myDb->exec_query($param);
				while($row = mysqli_fetch_array($result,MYSQL_ASSOC)){
					$param="INSERT INTO yj_login_record (user_id, login_time, login_ip) VALUES ('".$row['user_id']."','".date('y-m-d h:i:s',time())."','".getIp()."')";
					$result_insert = $myDb->exec_query($param);
					if($result_insert==TRUE){
						$result_obj->id = $row['user_id'];
  						$result_obj->username = $row['user_name'];
  						$result_obj->email = $row['user_email'];
  						$result_obj->result = "success";
					}
					else{
						$result_obj->result = "fail_serverbusy";
					}
				}
			}
			else{
				$result_obj->result = "fail_serverbusy";
			}
		}
		else{
			$result_obj->result = "fail_email";
		}
	}
	else{
		$result_obj->result = "fail_username";
	}
	$result_json = json_encode($result_obj);
	//ob_clean();
	echo $result_json;
?>